//
//  AppDelegate.m
//  energy
//
//  Created by 周曼迪 on 2021/7/6.
//

#import "AppDelegate.h"
/**bar*/
#import "SQTabBarController.h"
/**登陆*/
#import "SQLoginViewController.h"

#import "AppDelegate+GT.h"



@interface AppDelegate ()
@property (strong,nonatomic) SQTabBarController *tabBarController;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    
//    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
     UIViewController *view = [[UIViewController alloc]init];
      view.view.backgroundColor = [UIColor whiteColor];
      self.window.rootViewController =view;
      [self jump];
      [self.window makeKeyAndVisible];
    
    [self gt_beginWork];
    
    return YES;
}



/*
 * 判断登录状态
 */
- (void)jump{
    if (UID){//已登录
        [self initTabbarVC];
    }else{
        [self logAction];

    }
}


/*
 *  登陆`
 */
- (void)logAction{

    SQLoginViewController *log = [[SQLoginViewController alloc] initWithNibName:@"SQLoginViewController" bundle:nil];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:log];
    self.window.rootViewController = navi;
    
}

+ (AppDelegate *)getAppDelegate{
    return (AppDelegate *)[UIApplication sharedApplication].delegate;
}

- (void)initTabbarVC{
    SQTabBarController *tab = [[SQTabBarController alloc] init];
    self.window.rootViewController = tab;
    [self.window makeKeyAndVisible];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    SQ_LOG(@"%@",deviceToken);
    
    return [self gt_application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}


// 注册远程通知失败后，会调用这个方法
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    SQ_LOG(@"注册远程通知失败----%@", error.localizedDescription);
}

// 当接收到远程通知
// 前台（会调用）
// 从后台进入到前台（会调用）
// 完全退出再进入APP 不会执行这个方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    SQ_LOG(@"收到远程通知----%@", userInfo);
}

@end
